<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\ChOperationLog;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\ContactBlackRequest;
use App\CustHub\Service\ChConfigService;
use App\CustHub\Service\ChContactBlackService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;
use Psr\Http\Message\ResponseInterface;
use function Hyperf\Collection\value;

/**
 * 黑名单
 */
#[Controller('ch/black'),ApiAuth,VerifySignature]
class ChContactBlackController extends BaseController
{

    #[Inject]
    protected ChContactBlackService $service;

    #[Inject]
    protected ChConfigService $configService;

    /**
     * 黑名单列表
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('list')]
    public function list(): ResponseInterface
    {
        return $this->success($this->service->list($this->request->all()));
    }

    /**
     * 新增黑名单
     * @param ContactBlackRequest $request
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save'),ChOperationLog]
    public function save(ContactBlackRequest $request): ResponseInterface
    {
        return $this->service->saveBlack($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 删除黑名单
     * @param ContactBlackRequest $request
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @throws \Exception
     */
    #[PostMapping('delete'),ChOperationLog]
    public function delete(ContactBlackRequest $request): ResponseInterface
    {
        return $this->service->deleteBlack($request->all()) ? $this->success('删除成功') : $this->error('删除失败');
    }

    /**
     * 清空黑名单
     * @return ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @throws \Exception
     */
    #[PostMapping('clear'),ChOperationLog]
    public function clear(): ResponseInterface
    {
        return $this->service->clear($this->request->all()) ? $this->success() : $this->error();
    }

}